<!DOCTYPE html>
<html lang="en">
<head>
    <base href="../../">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/layui.css">
    <title>选择班级</title>
</head>
<body>
    <div class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">选择班级</label>
            <div class="layui-input-inline">
                <select name="classesID" id="classesID" lay-filter="choose_clsID">
                    <option value="" checked>请选择</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal share_link2" lay-submit lay-filter="saveBtn">确定</button>
            </div>
        </div>
    </div>

    <script src="layui.js"></script>
    <script src="js/axios.min.js" charset="utf-8"></script>
    <script src="js/clipboard.min.js" charset="utf-8"></script>
    <script>
        layui.use('form',function(){
            var form = layui.form;
            var $ = layui.$;
            var count=1;

            var banji=null;
            var tableID = layui.data("form_data").tableID;

            // 获取班级数据
            function get_banji(){
                axios.post('/formData/getClassesID')
                .then(function (response) {
                    var data = response.data;
                    var sele_banji = $('#classesID');
                    var ele;
                    for (var i=0; i<data.length; ++i){
                        ele = document.createElement('option');
                        ele.value = data[i];
                        ele.text = String(data[i]);
                        sele_banji.append(ele);
                        }
                    form.render();
                    console.log(response)
                }).catch(function (error) {
                    layer.msg("无法获取班级数据",{icon:2});
                }); 			
            }
            get_banji();

            $(".share_link2").on("click", function(){
                // var banji = data.field.classesID;
                
                
                var text = document.location.origin+"/formData/data_link?tableID="+tableID+"&class="+banji;
                $(".share_link2").attr("data-clipboard-text",text);
                console.log("d1")
                var clipboard = new ClipboardJS('.share_link2');
                clipboard.on('success', function(e) {
                    layer.msg('分享链接已复制！');
                    // alert('复制成功');
                    clipboard.destroy();  // 解决多次弹窗
                    e.clearSelection();
                    console.log("d2");

                    setTimeout(function(){
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    }, 1500);
                });

            });
            
            form.on('select(choose_clsID)', function (data) {
                // console.log("select ", data);
                banji=data.value;

            });

        });
    </script>
</body>
</html>